//
// Created by 1065246 on 2023/11/17.
//
#include<stdio.h>
#include<malloc.h>

typedef int QueueData;
typedef struct {
    QueueData data;
    struct DataNode *next;
} DataNode;

typedef struct {
    //队列长度
    int lenth;
    //头节点
    DataNode *front;
    //尾节点
    DataNode *rear;
} Queue;


void initQueue(Queue *queue) {
    queue->front = NULL;
    queue->rear = NULL;
}

void queuePush(Queue *queue, QueueData data) {
    DataNode *node = malloc(sizeof(DataNode));
    if (node == NULL) {
        return;
    }
    node->data = data;
    node->next = NULL;
    if (queue->front == NULL) {
        queue->front = queue->rear = node;
    } else {
        queue->rear->next = node;
        queue->rear = node;
    }
    queue->lenth++;
}

QueueData queuePop(Queue *queue) {
    QueueData queueData;
    if(queue->front!=NULL){
        DataNode * dataNodeFrontNew=queue->front->next;
        queue->front=dataNodeFrontNew;
        queue->lenth--;
        DataNode * dataNodeFront= queue->front;
        queueData=dataNodeFront->data;
        free(dataNodeFront);
    }
    return queueData;
}

void destroyQueue(Queue *queue){
    if(queue->front==NULL){
        return;
    }

    while (queue->lenth!=0){
        queuePop(queue);
    }

}